#pragma once
#include "RBTree.h"

namespace xy {
	template<class K, class V>
	class map {
		struct MapKeyofT {
			const K& operator()(const pair<const K, V>& kof) {
				return kof.first;
			}
		};
	public:
		typedef RBTree<K, pair<const K, V>, MapKeyofT> tree;
		typedef typename tree::iterator iterator;
		typedef typename tree::const_iterator const_iterator;
		pair<iterator, bool> insert(const pair<const K, V>& data) {
			return _t.insert(data);
		}

		iterator begin() {
			return _t.begin();
		}

		iterator end() {
			return _t.end();
		}

		const_iterator begin() const {
			return _t.begin();
		}

		const_iterator end() const {
			return _t.end();
		}

		V& operator[](const K& k) {
			pair<iterator, bool> ret = _t.insert(pair<const K, V> (k, V()));
			return ret.first->second;
		}
	private:
		tree _t;
	};
}